package com.jahentao.file.large;

import com.sun.org.apache.xerces.internal.dom.AttributeMap;
import com.sun.org.apache.xerces.internal.dom.DocumentImpl;
import com.sun.org.apache.xerces.internal.dom.ElementImpl;

/**
 * @author jahentao
 * @date 2018/7/8
 * @since 1.0
 */
public class RowElement extends ElementImpl {

    RowElement(String rowXmlLine) {
        super(new DocumentImpl(),"row");
        parseAttributes(rowXmlLine);
    }

    void parseAttributes(String rowXmlLine) {
        String attrName = null;
        String attrValue = null;
        if (rowXmlLine.startsWith("<row")) {
            // 记录的行
            //按照"分割是保险的
            String[] split = rowXmlLine.split("\"");
            boolean isFieldName = true;

            split[0] = split[0].substring(4);
            for (int i=0; i<split.length-1; i++) {
                if (isFieldName) {
                    attrName = split[i].substring(1, split[i].length()-1);
                } else {
                    attrValue = split[i];

                    setAttribute(attrName, attrValue);
//                System.out.println(attrName + ": " + attrValue);
                }
                isFieldName = !isFieldName;
            }
        }
    }

    void clearAttributes() {
        attributes = null;
    }

}
